CREATE PROCEDURE [dbo].[ProviderSave]
@Id						UNIQUEIDENTIFIER,
@Name					NVARCHAR(50),
@Location				NVARCHAR(50),
@Organization			NVARCHAR(50),
@Email					NVARCHAR(100),
@Latitude				FLOAT,
@Longitude				FLOAT,
@ConditionsTreated		NVARCHAR(250),
@ProceduresPerformed	NVARCHAR(250),
@Exclusions				NVARCHAR(250),
@AlternativeServices	NVARCHAR(250)

AS

DECLARE	@RowCount AS INT
DECLARE @Error AS INT

UPDATE	Provider
SET		[Name]				= ISNULL(@Name, [Name]), 
		Location			= ISNULL(@Location, Location), 	
		Organization		= ISNULL(@Organization, Organization),
		Email				= ISNULL(@Email, Email),
		Latitude			= ISNULL(@Latitude, Latitude),
		Longitude			= ISNULL(@Longitude, Longitude),
		ConditionsTreated	= ISNULL(@ConditionsTreated, ConditionsTreated), 	
		ProceduresPerformed	= ISNULL(@ProceduresPerformed, ProceduresPerformed), 	
		Exclusions			= ISNULL(@Exclusions, Exclusions), 	
		AlternativeServices	= ISNULL(@AlternativeServices, AlternativeServices)
WHERE	Id = @Id

SELECT @Error = @@ERROR, @RowCount = @@ROWCOUNT

IF @Error  <> 0
BEGIN
	RAISERROR('ERROR::ProviderSave:Error in',16,1)
END

IF @RowCount  > 0
BEGIN
	RETURN @RowCount 
END

--	If adding for first time enter all the details including Id
INSERT	INTO Provider (Id, [Name], Location, Organization, Email, Latitude, Longitude, ConditionsTreated, ProceduresPerformed, Exclusions, AlternativeServices)
VALUES	(@Id, @Name, @Location, @Organization, @Email, @Latitude, @Longitude, @ConditionsTreated, @ProceduresPerformed, @Exclusions, @AlternativeServices)

SELECT	@Error = @@ERROR, @RowCount = @@ROWCOUNT

IF @Error  <> 0
BEGIN
	RAISERROR('ERROR::ProviderNew:Error in',16,1)
END

RETURN @RowCount